package com.dkx.springbootwebsocket.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 杜科璇
 * @Description: TODO
 * @Date: 2025/10/31 18:49
 * @Version: 1.0
 */

// 在业务代码中使用
@Service
public class BusinessService {

    @Autowired
    private WebSocketMessageService messageService;

    public void someBusinessMethod() {
        // 发送点对点消息
        messageService.sendToUser("user1", "user2", "你好，这是点对点消息");

        // 发送群组消息
        List<String> groupUsers = Arrays.asList("user2", "user3", "user4");
        messageService.sendToGroup("user1", groupUsers, "这是群组消息");

        // 发送广播消息
        messageService.sendToAll("user1", "这是广播消息");

        // 检查用户在线状态
        boolean isOnline = messageService.isUserOnline("user2");
        System.out.println("用户2在线状态: " + isOnline);
    }
}